package com.czxy.changgou3.service;

import com.czxy.changgou3.feign.UserFeign;
import com.czxy.changgou3.pojo.User;
import com.czxy.utils.BCrypt;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author zhangmengxiang1@itcast.cn
 * @version 1.0
 * @date 2020/4/21
 */
@Service
public class AuthService {

    @Resource
    private UserFeign userFeign;

    /**
     * 用户登录
     * @param user
     * @return
     */
    public User login(User user){
        //远程查询用户
        User findUser = userFeign.findByUsername(user);
        if (findUser == null){
            return null;
        }
        //校验密码是否正确
        boolean checkpw = BCrypt.checkpw(user.getPassword(), findUser.getPassword());
        if(checkpw){
            return findUser;
        }
        return null;
    }

}
